package com.epoint.BookManager.service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.epoint.BookManager.dao.BookInfoDao;
import com.epoint.BookManager.domain.BookInfo;

public class BookInfoService {
	BookInfoDao bookInfoDao = new BookInfoDao();
	
	/**
	 * 查询所有数据
	 * @param bookName
	 * @param bookType
	 * @param pageIndex
	 * @param PageSize
	 * @param sortField
	 * @param sortOrder
	 * @return
	 * @throws SQLException
	 */
		public List<BookInfo>	getBookList(String bookName,int bookType,int pageIndex,int PageSize,String sortField,String sortOrder) throws SQLException {
			List<BookInfo> books =(ArrayList<BookInfo>) bookInfoDao.getBookList(bookName, bookType, pageIndex, PageSize, sortField, sortOrder);
			return books;
	}
		/**
		 * 添加书籍
		 * @param bookInfo
		 * @return
		 */
		public boolean addBook(BookInfo bookInfo) {
			int info = bookInfoDao.addBookInfo(bookInfo);
			return info==1;	
		}
		
		/**
		 * 删除书籍
		 * @throws SQLException 
		 */
		public boolean deleteBook(String bookid) throws SQLException {
			int deleteBookinfo = bookInfoDao.deleteBookinfo(bookid);
			if(deleteBookinfo==0) {
				return false;
			}else {
				return true;
			}
		}
		
		/**
		 * 修改书籍信息
		 * @param booktype
		 * @param publisher
		 * @param bookid
		 * @return
		 */
		public boolean edit(int booktype,String publisher,String bookid ) {
			
			int updateBookInfo = bookInfoDao.updateBookInfo(booktype,publisher,bookid);
			if (updateBookInfo==0) {
				return false;
			}else {
				return true;
			}
		}
		
		
		/**
		 * 根据bookid查询book
		 * @param bookid 
		 * @return
		 */
		public BookInfo getBookByBookId(String bookid) {
			return bookInfoDao.queryBookInfoByID(bookid);
		}
		
		
}
